package com.lxx.utils;

import javax.servlet.http.HttpSession;

import com.lxx.modules.sys.entity.SysUser;

import static com.lxx.utils.Constant.SESSION_USER_FLAG;

public class SessionUtils {
	
	public static final boolean isLogged(HttpSession session) {
		Object o = session.getAttribute(SESSION_USER_FLAG);
		return o != null;
	}
	
	public static final void saveUser2Session(HttpSession session, SysUser user) {
		SessionInfo sessionInfo = new SessionInfo();
		sessionInfo.setUser(user);
		session.setAttribute(SESSION_USER_FLAG, sessionInfo);
	}
	
	public static final void invalidateSession(HttpSession session) {
		session.invalidate();
	}
	
	public static final SysUser sessionUser(HttpSession session) {
		SessionInfo o = (SessionInfo) session.getAttribute(SESSION_USER_FLAG);
		if (o != null) {
			return o.getUser();
		} else {
			return null;
		}
	}

}
